//------------------------------------------------------------
// 事件系统辅助类 - 简化事件系统的使用
//------------------------------------------------------------

using System;

/// <summary>
/// 事件系统辅助类
/// </summary>
public static class EventHelper
{
    /// <summary>
    /// 订阅事件
    /// </summary>
    public static void Subscribe(int id, EventHandler<GameEventArgs> handler)
    {
        EventComponent.Instance?.Subscribe(id, handler);
    }

    /// <summary>
    /// 取消订阅事件
    /// </summary>
    public static void Unsubscribe(int id, EventHandler<GameEventArgs> handler)
    {
        EventComponent.Instance?.Unsubscribe(id, handler);
    }

    /// <summary>
    /// 抛出事件（延迟分发）
    /// </summary>
    public static void Fire(object sender, GameEventArgs e)
    {
        EventComponent.Instance?.Fire(sender, e);
    }

    /// <summary>
    /// 抛出事件（立即分发）
    /// </summary>
    public static void FireNow(object sender, GameEventArgs e)
    {
        EventComponent.Instance?.FireNow(sender, e);
    }

    /// <summary>
    /// 订阅事件（使用EventType枚举）
    /// </summary>
    public static void Subscribe(EventType eventType, EventHandler<GameEventArgs> handler)
    {
        Subscribe((int)eventType, handler);
    }

    /// <summary>
    /// 取消订阅事件（使用EventType枚举）
    /// </summary>
    public static void Unsubscribe(EventType eventType, EventHandler<GameEventArgs> handler)
    {
        Unsubscribe((int)eventType, handler);
    }

    /// <summary>
    /// 抛出事件（使用EventType枚举）
    /// </summary>
    public static void Fire(EventType eventType, object sender, GameEventArgs e)
    {
        if (e.Id != (int)eventType)
        {
            throw new Exception($"Event type mismatch: expected {(int)eventType}, got {e.Id}");
        }
        Fire(sender, e);
    }

    /// <summary>
    /// 抛出事件（立即分发，使用EventType枚举）
    /// </summary>
    public static void FireNow(EventType eventType, object sender, GameEventArgs e)
    {
        if (e.Id != (int)eventType)
        {
            throw new Exception($"Event type mismatch: expected {(int)eventType}, got {e.Id}");
        }
        FireNow(sender, e);
    }
}

